Class ClientProgressRepLink extends LinkedReplicationInfo;

var float NextRepTime;

var SRAchievementsBase AchievementObject;
var ServerPerksMut Mut;

var int	RBurningCrossbowKillsStat;


replication
{
	reliable if( Role==ROLE_Authority && bNetOwner )
		RBurningCrossbowKillsStat;
	// Functions server can call.
//	reliable if( Role == ROLE_Authority )
//		;

//	reliable if( Role < ROLE_Authority )
//		;
}


simulated static final function ClientProgressRepLink FindAchievements( PlayerController Other )
{
	local LinkedReplicationInfo L;
	local ClientProgressRepLink C;

	if( Other.PlayerReplicationInfo==None )
	{
		foreach Other.DynamicActors(Class'ClientProgressRepLink',C)
			if( C.Owner==Other )
			{
				C.RepLinkBroken();
				return C;
			}
		return None; // Not yet init.
	}
	for( L=Other.PlayerReplicationInfo.CustomReplicationInfo; L!=None; L=L.NextReplicationInfo )
		if( ClientProgressRepLink(L)!=None )
			return ClientProgressRepLink(L);
	if( Other.Level.NetMode!=NM_Client )
		return None; // Not yet init.
	foreach Other.DynamicActors(Class'ClientProgressRepLink',C)
		if( C.Owner==Other )
		{
			C.RepLinkBroken();
			return C;
		}
	return None;
}

simulated function Tick( float DeltaTime )
{
	local PlayerController PC;
	local LinkedReplicationInfo L;

	if( Level.NetMode==NM_DedicatedServer )
	{
		Disable('Tick');
		return;
	}
	PC = Level.GetLocalPlayerController();
	if( Level.NetMode!=NM_Client && PC!=Owner )
	{
		Disable('Tick');
		return;
	}
	if( PC.PlayerReplicationInfo==None )
		return;
	Disable('Tick');
//	Class'SRLevelCleanup'.Static.AddSafeCleanup(PC);

	if( PC.PlayerReplicationInfo.CustomReplicationInfo!=None )
	{
		for( L=PC.PlayerReplicationInfo.CustomReplicationInfo; L!=None; L=L.NextReplicationInfo )
			if( L==Self )
				return; // Make sure not already added.

		NextReplicationInfo = None;
		for( L=PC.PlayerReplicationInfo.CustomReplicationInfo; L!=None; L=L.NextReplicationInfo )
			if( L.NextReplicationInfo==None )
			{
				L.NextReplicationInfo = Self; // Add to the end of the chain.
				return;
			}
	}
	PC.PlayerReplicationInfo.CustomReplicationInfo = Self;
}
simulated final function RepLinkBroken() // Called by GUI when this is noticed.
{
	Enable('Tick');
	Tick(0);
}

Auto state RepSetup
{
Begin:
	if( Level.NetMode==NM_Client )
		Stop;
	Sleep(1.f);
	NetUpdateFrequency = 0.5f;

	if( NetConnection(AchievementObject.PlayerOwner.Player)!=None ) // Network client.
	{
		// Do nothing
	}
	GoToState('');
}

defaultproperties
{
	bAlwaysRelevant=false
	bOnlyRelevantToOwner=true
	bOnlyDirtyReplication=true
}